package com.winhxd.b2c.customer.util;

import com.winhxd.b2c.common.domain.message.condition.MiniMsgCondition;
import com.winhxd.b2c.common.domain.message.condition.MiniTemplateData;
import com.winhxd.b2c.common.domain.message.condition.SMSCondition;
import com.winhxd.b2c.common.util.JsonUtil;
import com.winhxd.b2c.common.util.MessageSendUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
 * 提现Util工具类
 * @author zhanghuan
 * @date  2018年8月23日 下午12:54:48
 * @version 
 */
public class SendMsgUtil {

    private static final Logger logger = LoggerFactory.getLogger(SendMsgUtil.class);

    private SendMsgUtil() {

    }
    /**
     * 生成云信消息对象
     *
     * @param storeId
     * @param storeMsg
     * @param createdBy
     * @param expiration
     * @param msgType
     * @param pageType
     * @param audioType
     * @return
     * @author wangbin
     * @date 2018年8月16日 下午5:24:49
     * @Description
     */
//    public static NeteaseMsgCondition genNeteaseMsgCondition(Long storeId, String storeMsg, String createdBy, int expiration,
//                                                             int msgType, short pageType, short categoryType, int audioType) {
//		NeteaseMsgCondition neteaseMsgCondition = new NeteaseMsgCondition();
//		neteaseMsgCondition.setCustomerId(storeId);
//		NeteaseMsg neteaseMsg = new NeteaseMsg();
//		neteaseMsg.setMsgContent(storeMsg);
//		neteaseMsg.setAudioType(audioType);
//		neteaseMsg.setPageType(pageType);
//		neteaseMsg.setMsgCategory(categoryType);
//		neteaseMsg.setMsgType(msgType);
//		neteaseMsg.setCreatedBy(createdBy);
//		neteaseMsg.setExpiration(expiration);
//		neteaseMsgCondition.setNeteaseMsg(neteaseMsg);
//		return neteaseMsgCondition;
//    }

    public static SMSCondition getSmsMsgCondition(String mobile, String content) {
        SMSCondition smsCondition = new SMSCondition();
        smsCondition.setMobile(mobile);
        smsCondition.setContent(content);
        return smsCondition;
    }

    public static MiniMsgCondition genMiniMsgCondition(String openid, String page, short msgType2C, String emphasisKeyword, List<MiniTemplateData> temData) {
        MiniMsgCondition miniMsgCondition = new MiniMsgCondition();
        miniMsgCondition.setToUser(openid);
        miniMsgCondition.setPage(page);
        miniMsgCondition.setMsgType(msgType2C);
        miniMsgCondition.setData(temData);
        miniMsgCondition.setEmphasisKeyword(emphasisKeyword);
        return miniMsgCondition;
    }
    /**
     * 发送云信消息
     * @param messageServiceClient
     * @param storeMsg
     * @param categoryType
     * @param storeId
     * @author wangxiaoshun
     */
//    public static void sendMsg(MessageSendUtils messageServiceClient, String storeMsg, Short categoryType, Long storeId){
//        try {
//            // 发送云信
//            String createdBy = "";
//            int expiration = 0;
//            int msgType = 0;
//            int audioType = 0;
//            short pageType = MsgPageTypeEnum.NOTICE.getPageType();
//            NeteaseMsgCondition neteaseMsgCondition = PayUtil.genNeteaseMsgCondition(storeId, storeMsg, createdBy, expiration, msgType,
//                    pageType, categoryType, audioType);
//            messageServiceClient.sendNeteaseMsg(neteaseMsgCondition);
//        } catch (Exception e) {
//            logger.error("门店提现发送消息:storeId={},发送消息：{} 失败", storeId, storeMsg);
//            logger.error("门店提现发送消息失败：", e);
//        }
//    }

    /**
     * 发送端信消息
     * @param messageServiceClient
     * @param mobile
     * @param content
     * @author wangxiaoshun
     */
    public static void sendSmsMsg(MessageSendUtils messageServiceClient, String mobile, String content){
        try {
            SMSCondition smsCondition = SendMsgUtil.getSmsMsgCondition(mobile, content);
            messageServiceClient.sendSms(smsCondition);
        } catch (Exception e) {
            logger.error("门店提现发送短信:mobile={},发送消息：{} 失败", mobile, content);
            logger.error("门店提现发送消短信失败：", e);
        }
    }

    public static void sendMiniTemplateMsg(MessageSendUtils messageServiceClient, String openid, String page, short msgType2C, String emphasisKeyword, List<MiniTemplateData> temData){
        MiniMsgCondition miniMsgCondition = null;
        try {
            miniMsgCondition = genMiniMsgCondition(openid, page, msgType2C, emphasisKeyword, temData);
            messageServiceClient.sendMiniTemplateMsg(miniMsgCondition);
        } catch (Exception e) {
            logger.error("分销商提现发送小程序模板消息失败:{}", JsonUtil.toJSONString(miniMsgCondition));
            logger.error("分销商提现发送小程序模板消息失败：", e);
        }
    }
}
